<?php

namespace App\Models;

use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\SoftDeletes;

class House extends Model
{
    use HasFactory;
    use SoftDeletes;

    protected $table = 'zfm_house';


    /**
     * @funcrion  房源与用户行为的关联关系
     */
    public function beHavIoVrs()
    {
        return $this->hasMany(Bebaviour::class, 'id', 'house_id');
    }


    /**
     *  '显示房屋信息
     * @return House[]|\Illuminate\Database\Eloquent\Collection
     */
    public static function showList()
    {
        return self::query()->paginate(8);
    }

    /**
     * @function  详情数据
     */
    public static function houseDeaTe($id)
    {
        return self::query()->find($id);
    }

    /**
     * 搜索方法
     * @param $data
     */
    public static function search($data, $where)
    {
        return self::where($data, 'like', "% $where%")->get(['name', 'location', 'rent', 'created_at']);
    }

    /**
     * @function  删除数据
     * @param $id
     * @param $idDate
     * @return mixed
     */
    public static function del($id, $idDate)
    {
        return self::where([$id => $idDate])->delete();
    }

    /**
     * @function 修改数据
     * @param $id
     * @param $data
     * @return mixed
     */
    public static function upDatHouse($id, $data)
    {
        $data = implode($data, '.');
        return self::where($id, $data['id'])->update($data);
    }

    /**
     * @function  查看看房时间
     */
    public static function openHomeModel($startTime, $timeWhere)
    {
        return self::query()->where($startTime, $timeWhere . ' 00:00:00')->get();
    }

}
